package com.example.demo.service;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;

@WebService
public class UserServiceImpl implements UserService {

    /**
     * 供客户端调用方法  该方法是非静态的，会被发布
     *
     * @param name 传入参数
     * @return String 返回结果
     */
    @WebMethod
    public String getValue (@WebParam(name = "name") String name) {
        return "欢迎你！ " + name;
    }

    /**
     * 方法上加@WebMentod(exclude=true)后，此方法不被发布；
     *
     *  请求：
     *  http://127.0.0.1:8080/Service/ServiceHello
     *
     *  Content-Type: text/xml
     *  <?xml version="1.0" encoding="UTF-8"?>
     * <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://service.demo.example.com/">
     *     <soapenv:Body>
     *         <ws:getString>
     *             <name>
     *                 Owater
     *             </name>
     *         </ws:getString>
     *     </soapenv:Body>
     * </soapenv:Envelope>
     * @param name
     * @return
     */
    @WebMethod(exclude = true)
    public String getHello (String name) {
        return "你好！ " + name;
    }

    /**
     * 静态方法不会被发布
     *
     * @param name
     * @return
     */
    public static String getString (String name) {
        return "再见！" + name;
    }

    public static void main (String[] args) {
        /*参数:1,本地的服务地址;
           2,提供服务的类;
      */
        Endpoint.publish("http://127.0.0.1:8080/Service/ServiceHello", new UserServiceImpl());
        System.out.println("发布成功!");
        //发布成功后 在浏览器输入 http://192.168.1.105:8080/Service/ServiceHello?wsdl
    }

}
